<div id="doc">
    
    <ul id="navigation" class="treeview">
    
        <?php
        $sql_raiz = "SELECT * FROM docarea 
        WHERE sta_id='1' AND doc_tip_id='{$linha_doctipo['doc_tip_id']}'
        ORDER BY doc_are_nome";
        $res_raiz = sql($sql_raiz);
        while($linha_raiz = mysql_fetch_array($res_raiz)) {
        ?>
        <li class="collapsable">
            
            <div class="hitarea collapsable-hitarea"></div>
            
            <a href="#"><?=$linha_raiz['doc_are_nome'];?></a>
            
            <ul style="display: block;">
    
                <?php
                $sql_sub2 = "SELECT * FROM docarea 
                WHERE sta_id='1' AND doc_are_id='{$linha_raiz['doc_are_id2']}' ORDER BY doc_are_nome";
                $res_sub2 = sql($sql_sub2);
                while($linha_sub2 = mysql_fetch_array($res_sub2)) {
                ?>
                <li class="expandable">
                    
                    <div class="hitarea expandable-hitarea"></div>
                    <a href="#"><?=$linha_sub2['doc_are_nome'];?></a>
    
                    <ul>
    
                        <?php
                        $sql_sub3 = "SELECT * FROM docarea 
                        WHERE sta_id='1' AND doc_are_id='{$linha_sub2['doc_are_id2']}' ORDER BY doc_are_nome";
                        $res_sub3 = sql($sql_sub3);
                        while($linha_sub3 = mysql_fetch_array($res_sub3)) {
                        ?>
                        <li class="last">
                            
                            <a href="#"><?=$linha_sub3['doc_are_nome'];?></a>
    
                            <ul style="display: none;">
    
                                <?php
                                $sql_file3 = "SELECT * FROM doc 
                                WHERE sta_id='1' AND doc_are_id='{$linha_sub3['doc_are_id2']}' ORDER BY doc_id DESC";
                                $res_file3 = sql($sql_file3);
                                while($linha_file3 = mysql_fetch_array($res_file3)) {
                                ?>
                                    <li class="last">
                                       <a href="service/<?=$linha_file3['doc_url'];?>" target="_blank"><?="{$linha_file3['doc_nome']} - <b>".todatabr($linha_file3['doc_data'])."</b>&nbsp;&nbsp;-&nbsp;&nbsp;{$linha_file3['doc_hora']} Z";?></a>
                                    </li>
                                <?php
                                }
                                ?>
    
                            </ul>
    
                        </li>
                    <? 
                    }
                    
                    $sql_file2 = "SELECT * FROM doc 
                    WHERE sta_id='1' AND doc_are_id='{$linha_sub2['doc_are_id']}' ORDER BY doc_id DESC";
                    $res_file2 = sql($sql_file2);
                    while($linha_file2 = mysql_fetch_array($res_file2)) {    
                    ?>
                    <li class="last">
                        <a href="service/<?=$linha_file2['doc_url'];?>" target="_blank"><?="{$linha_file2['doc_nome']} - <b>".todatabr($linha_file2['doc_data'])."</b>&nbsp;&nbsp;-&nbsp;&nbsp;{$linha_file2['doc_hora']} Z";?></a>
                    </li>
    
                    <?php 
                    } 
                    ?>
                    </ul>
    
                </li>
                <? } 
                
                $sql_raiz1 = "SELECT * FROM doc 
                WHERE sta_id='1' AND doc_are_id='{$linha_raiz['doc_are_id']}' ORDER BY doc_id DESC";
                $res_raiz1 = sql($sql_raiz1);
                while($linha_raiz1 = mysql_fetch_array($res_raiz1)) {
                ?>
                    <li class="last">
                        <a href="service/<?=$linha_raiz1['doc_url'];?>" target="_blank"><?="{$linha_raiz1['doc_nome']} - <b>".todatabr($linha_raiz1['doc_data'])."</b>&nbsp;&nbsp;-&nbsp;&nbsp;{$linha_raiz1['doc_hora']} Z";?></a>
                    </li>
                <?php
                }
                ?>
                
            </ul>
            
        </li>
        <?php
        }
        ?>
    </ul>
    
</div>